import { useTable, LIST_TYPE } from '@crud/index';
import { getLecAllList } from '@/api/crm-agency/kgj/lecturer';
import { formatPrivateMobile } from '@/utils';
// 查询

export const extendTypeMap: any = { 1: '考古加', 2: '大赢加', 3: '考古加/大赢家', 4: '创意', 5: '考古加/创意', 6: '大赢加/创意', 7: '考古加/大赢加/创意' };
// 对应选中值
export const extendTypeSelectMap: any = { 1: [1], 2: [2], 3: [1, 2], 4: [4], 5: [1, 4], 6: [2, 4], 7: [1, 2, 4] };

// 表格
export const useTableList = (options: any = {}) => {
  const columns: any = [
    { label: '账号名称', prop: 'name', minWidth: 160, fixed: 'left' },
    { label: '手机号', minWidth: 160, prop: 'mobile', render: (e) => Number(e.row.mobile) ? formatPrivateMobile(e.row.mobile) : e.row.mobile },
    { label: '加入时间', prop: 'add_time', minWidth: 177, type: 'dateTime' },
    { label: '推广产品', prop: 'extend_type', minWidth: 160, render: (s: any) => extendTypeMap[s.row.extend_type] },
    { label: '跟进人', minWidth: 160, prop: 'follower' },
    { label: '操作', align: 'center', render: 'actions', width: 120, fixed: 'right' }
  ];
  const timeChange = (values:any[]) => {
    let from = undefined;
    let to = undefined;
    if (values && values.length > 0) {
      from = values[0];
      to = values[1];
    }
    return { from, to };
  };
  return useTable({
    ...options,
    type: LIST_TYPE.AGENCY,
    params: {
      keyword: '',
      follower: '',
      from_dt: undefined,
      to_dt: undefined,
      _dateRange: []
    },
    columns: columns,
    getList: ({ data, params }:{data: Record<string, any>, params: any}) => {
      const { keyword, follower, _dateRange } = data;
      let { from_dt, to_dt } = params;
      const { from, to } = timeChange(_dateRange);
      from_dt = from;
      to_dt = to;
      data = { keyword, follower, from_dt, to_dt };
      return getLecAllList({ data, params });
    }
  });
};
